﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using com.vs.DataAccess;
using com.vs.DataAccess.DO;
using com.vs.General;
using com.vs.General.RF;
using com.vs.Receiving.BL;

namespace com.vs.RF.Web
{
    public class LPNEntryHandling :RFHandlingPage
    {
        string stLPN = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            stSourcePage = "receiving/LPNEntry.aspx";
            stTargetPage = "receiving/LPNEntry.aspx";
            go();
        }

        protected override void parseRequest()
        {
            stLPN = Request["tbLPN"];
            if (StringManager.IsEmpty(stLPN))
            {
                stError = MessageManager.MSG_RCP_016;//"错误：托盘号不能为空"; //
                return;
            }
        }

        protected override void procData()
        {
            ReceivingHelper helper = null;
            ReceiptContainerDO rcDO = null;
            ReceivingPreferenceDO prefDO = null;
            Queue<int> qLPNQty = null;

            try
            {
                rcDO = (ReceiptContainerDO)Session[RFSupport.RECEIPT_CONTAINER_DO];
                if (rcDO == null)
                {
                    stError = MessageManager.MSG_GEN_004;//"错误：系统缓存丢失，请重新登录";
                    return;
                }
                qLPNQty = (Queue<int>)Session[RFSupport.CONTAINER_QUANTITY_LIST];
                if (qLPNQty == null || qLPNQty.Count < 1)
                {
                    stError = MessageManager.MSG_GEN_004;//"错误：系统缓存丢失，请重新登录";
                    return;
                }
                rcDO.QUANTITY = qLPNQty.Dequeue();
                rcDO.CONTAINER_ID = stLPN;

                prefDO = (ReceivingPreferenceDO)Session[RFSupport.RECEIVING_PREFERENCE_DO];
                if (prefDO == null)
                {
                    stError = MessageManager.MSG_GEN_004; //错误：系统缓存丢失，请重新登录";
                    return;
                }

                helper = new ReceivingHelper();
                stError = helper.CheckIn(rfSess, rcDO, prefDO);
                if (!StringManager.IsEmpty(stError))
                    return;
                else
                {
                    Session[RFSupport.CONTAINER_NUMBER] = (int)Session[RFSupport.CONTAINER_NUMBER] + 1;
                    Session[RFSupport.CONTAINER_QUANTITY_LIST] = qLPNQty;

                    if (Convert.ToInt32(Session[RFSupport.CONTAINER_COUNT]) < Convert.ToInt32(Session[RFSupport.CONTAINER_NUMBER]))
                    {
                        stTargetPage = "ItemEntry.aspx";
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.LogException(rfSess, ex);
                stError = ex.Message;
            }
        }

    }
}
